package com.lagou.rpc.provider.server;

import org.I0Itec.zkclient.ZkClient;
import org.springframework.stereotype.Service;

/**
 * @author: liufh
 * @create: 2021-12-27 21:10
 **/
@Service
public class ZookeeperServer {

    /**
     * 创建节点
     */
    public void createNote() {
        ZkClient zkClient = new ZkClient("192.168.44.128:2181");

        String path = "/homework/service";
        boolean exists = zkClient.exists(path);
        if (!exists) {
            zkClient.createPersistent(path, true);
        }
        String ipPath = path + "/IP" + "8898";
        boolean ipExists = zkClient.exists(ipPath);
        if (!ipExists) {
//            zkClient.createPersistent(ipPath, "127.0.0.1:8899");
            zkClient.createEphemeral(ipPath, "127.0.0.1:8898");
        }
        System.out.println("节点创建完成");
    }

}
